package com.lhn.bbs.controller;


import com.lhn.bbs.dto.ActionResult;
import com.lhn.bbs.service.ReplyService;
import com.lhn.bbs.vo.ReplyAddVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RequestMapping("/reply")
@RestController
@Slf4j
public class ReplyController {


    @Autowired
    private ReplyService replyService ;

    /**
     * 主题帖的评论回复功能
     * @param replyAddVo
     * @return
     */
    @RequestMapping(value = "/replyadd" ,method = RequestMethod.POST)
    public ActionResult replyadd(@RequestBody ReplyAddVo replyAddVo){

        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
//        System.out.println(formatter.format(date));
        String format = formatter.format(date);
        replyAddVo.setReplytime(format);
//        log.info("============"+replyAddVo);

        return  replyService.replyadd(replyAddVo);
    }

    /**
     * 查询我的回复帖
     * @param userid 用户id
     * @param page  第几页
     * @param limit 每页有多少条
     * @return  返回值类型是 ActionResult
     */
    @RequestMapping(value = "/replythemebyuserid",method = RequestMethod.GET)
    public ActionResult replythemeByuserid(@RequestParam(value = "userid") Integer userid,
                                           @RequestParam(value = "page") Integer page,
                                           @RequestParam(value = "limit") Integer limit){

        log.info("++++++"+userid+"++++"+page+"+++"+limit);

        return replyService.replythemeByUserid(userid,page,limit);
    }

    //根据replyid删除回复内容
    @RequestMapping(value = "/deletereply",method=RequestMethod.GET)
    public ActionResult deleteReplyById(@RequestParam(value = "replyid") Integer replyid){

        log.info("++++++"+replyid);
        return replyService.deleteReplyByid(replyid);
    }
}
